package com.example.prison.mapper;

import com.example.prison.entity.VisitorList;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【visitor_list】的数据库操作Mapper
* @createDate 2024-06-03 15:14:59
* @Entity com.example.prison.entity.VisitorList
*/
@Mapper
public interface VisitorListMapper extends BaseMapper<VisitorList> {

    @Select("<script>select * from visitor_list " +
            " <where> " +
            " <if test=\"visitorName != null and visitorName != ''\">and visitor_name like concat('%',#{visitorName},'%') </if> " +
            " <if test=\"beginTime != null and beginTime != ''\">and visitor_time &gt;= #{beginTime} </if> " +
            " <if test=\"endTime != null and endTime != ''\">and visitor_time &lt;= #{endTime} </if> " +
            " </where> " +
            "order by id desc</script>")
    List<VisitorList> get(@Param("visitorName")String visitorName, @Param("beginTime")String beginTime, @Param("endTime")String endTime);

    @Insert("insert into visitor_list(visitor_name, visitor_time, end_time) " +
            "values (#{visitorName}, #{visitorTime}, #{endTime}")
    int add(VisitorList visitor);

    @Delete("<script>delete from visitor_list where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteVisitorList(@Param("ids") Integer[] ids);

//    @Update("update visitor_list set visitor_name=#{visitor.visitorName},visitor_time=#{visitor.visitorTime},end_time=#{visitor.endTime} where id = #{id}")
    @Update({"<script> UPDATE visitor_list",
            "<set>",
            "<if test='visitor.visitorName != null'>visitor_name = #{visitor.visitorName},</if>",
            "<if test='visitor.visitorTime != null'>visitor_time = #{visitor.visitorTime},</if>",
            "<if test='visitor.endTime != null'>end_time = #{visitor.endTime},</if>",
            "</set>",
            "where id = #{id} </script>"})
    int updateVisitorList(VisitorList visitor,Integer id);

    @Select("select * from visitor_list where id=#{id}")
    VisitorList getById(@Param("id") Integer id);

    @Select("select * from visitor_list where visitor_card=#{idCard} order by visitor_time desc LIMIT 1")
    VisitorList getByIdCard(@Param("idCard") String idCard);


}




